package com.woniu.cq.medical.controller;


import com.woniu.cq.medical.common.PageResult;
import com.woniu.cq.medical.common.Result;
import com.woniu.cq.medical.controller.form.DutyQueryForm;
import com.woniu.cq.medical.entity.Duty;
import com.woniu.cq.medical.service.DutyService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2020-09-05
 */
@RestController
@RequestMapping("/medical/duty")
public class DutyController {

    @Autowired
    private DutyService dutyService;

    /**
     * 取得当前时间往后7天的的排班时间
     * @param doctorId
     * @return
     * @throws ParseException
     */
    @GetMapping("selectDutyDateList")
    public Result selectDutyDateList(Integer doctorId) throws ParseException {
        List<Date> dates = dutyService.queryDutyDateList(doctorId);
        return Result.success(dates);
    }

    /**
     * 返回排班表
     * @param doctorId
     * @return
     */
   @GetMapping("selectDutyList")
    public Result selectDutyList(Integer doctorId){
        List<Duty> duties = dutyService.queryDutyList(doctorId);
        return Result.success(duties);
    }


    @GetMapping("pageQuery")
    public PageResult getPage(@RequestParam(defaultValue = "1")int pageIndex, @RequestParam(defaultValue = "15")int pageSize,
                              String administrativeName, String doctorName, Date dutyDateBefore, Date dutyDateAfter){
        PageResult pageResult = dutyService.pageQuery(pageIndex, pageSize, administrativeName, doctorName,dutyDateBefore, dutyDateAfter);
        return pageResult;
    }
    @PutMapping("modifyDoctorDuty")
    @RequiresRoles({"dean"})
    public Result modifyDoctorDuty(DutyQueryForm dutyQueryForm){
        Result result=dutyService.modifyDoctorDuty(dutyQueryForm);
       return result;
    }



}

